﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CsQuery;
using System.Net;
using System.IO;

namespace Crawler_v1.ui
{
    public partial class testCsQuery : Form
    {
        public testCsQuery()
        {
            InitializeComponent();
        }

        #region HttpWebRequest异步GET

        public static void AsyncGetWithWebRequest(string url)
        {
            var request = (HttpWebRequest)WebRequest.Create(new Uri(url));
            request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
        }
        private static void ReadCallback(IAsyncResult asynchronousResult)
        {
            var request = (HttpWebRequest)asynchronousResult.AsyncState;
            var response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            using (var streamReader = new StreamReader(response.GetResponseStream()))
            {

                var resultString = streamReader.ReadToEnd();
                Console.WriteLine(resultString);

                CQ dom = resultString;


            }
        }

        #endregion


        private void button1_Click(object sender, EventArgs e)
        {
            AsyncGetWithWebRequest("http://fec.mofcom.gov.cn/article/fwydyl/");


            /*
            var promise = CQ.CreateFromUrlAsync("http://fec.mofcom.gov.cn/article/fwydyl/tjsj/");

            promise.Then(responseSuccess =>
            {

                var Dom = responseSuccess.Dom;
                var section=Dom["section.newList_01"];
                Dom["section.newList_01 ul li a"].ToList();
            }, responseFail =>
            {

            });
            */
        }
    }
}
